package com.his.registration.controller;

import com.his.common.Result;
import com.his.registration.pojo.MedicalRecord;
import com.his.registration.service.MedicalRecordService;
import org.apache.ibatis.annotations.Select;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @BelongsProject: workspace-idea
 * @BelongsPackage: com.his.registration.controller
 * @Author: ZhangYing
 * @Date: 2023/7/3 14:18
 * @Description:
 */
@RestController
@CrossOrigin
@RequestMapping("/medicalRecord")
public class MedicalRecordController {
    @Autowired
    private MedicalRecordService medicalRecordService;

    @RequestMapping("/insert")
    //动态插入病历
    public Result insert(MedicalRecord medicalRecord){
        int result = medicalRecordService.insert(medicalRecord);
        //得到最新插入的id
        int insertId = medicalRecordService.getInsertId();
        return Result.success(insertId);
    }

    //拿着病历中的挂号id去表中得到id
    @RequestMapping("/getIdByRegisterId")
    public Result getIdByRegisterId(int registerId){
        int id = medicalRecordService.getIdByRegisterId(registerId);
        return Result.success(id);
    }

    //动态修改病历内容
    @RequestMapping("/update")
    public Result update(MedicalRecord medicalRecord){
        int result = medicalRecordService.update(medicalRecord);
        return Result.success("成功更新"+result+"条病历信息");
    }
}
